--[[/**
-- * 
-- * 生命值每降低[0]%，所造成的伤害提升[1]%
-- * [2]表现buffid 提高伤害了把表现buff加上 没有则移除
-- *
-- */]]

---@class BuffEffect45100 : BaseBuffEffect
BuffEffect45100 = ClientFight.CreateClass("BuffEffect45100", ClientFight.BaseBuffEffect)
local t = BuffEffect45100

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local fighter = buff.target; -- 被伤害者
    local hp = fighter.hp;
    local maxHp = FighterAttributeManager.getFightAttr(fighter, FighterAttributeEnum.HP);
    local lostHp = maxHp - fighter.hp;
    local showBuffId = buff.buffBean.f_BuffEffectValue[3];
    local showBuffBean = BuffManager.getBuffBean(showBuffId, buff.source);
    -- 当前血量百分比
    local nowPercent = (lostHp * Global.TEN_THOUSANDTH / maxHp);
    local multiple = nowPercent / buff.buffBean.f_BuffEffectValue[1];
    local showBuff = nil;
    if (showBuffBean ~= nil) then
        showBuff = BuffManager.getBuffByModel(fighter, showBuffBean, buff.source, true);
    end
    if (multiple <= 0) then
        if (showBuff ~= nil) then
            BuffManager.removeFighterBuff(fight, fighter, showBuff, true);
        end
        return IBuffEffect.FAIL;
    end
    local addVal = buff.buffBean.f_BuffEffectValue[2] * multiple;

    buff.attributes.attributes = {};
    buff.attributes.attributes[FighterAttributeEnum.DAMAGE.id] = addVal;
    if (showBuff == nil and showBuffBean ~= nil) then
        -- 加个表现buff
        BuffManager.addBuff(fight, buff.skill, buff.source, fighter, true, showBuffId, buff.buffBean.f_BuffEffectValue[4]);
    end

    SkillRoleMgr.savePathFile("[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
            .. buff.modelId .. " 触发生命值每降低百分比，增加伤害：" .. addVal);

    ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
    return IBuffEffect.SUCCESS_ATTRI_HAS_CHANGE;
end

function t:remove(fight, buff, force, ...)
    local parameters = {...};
    local fighter = buff.target;
    local showBuffId = buff.buffBean.f_BuffEffectValue[2];
    local showBuffBean = BuffManager.getBuffBean(showBuffId, buff.source);
    if (showBuffBean ~= nil) then
        local showBuff = BuffManager.getBuffByModel(fighter, showBuffBean, buff.source, true);
        if (showBuff ~= nil) then
            BuffManager.removeFighterBuff(fight, fighter, showBuff, true);
        end
    end
    return ClientFight.BaseBuffEffect.remove(self, fight, buff, ...);
end

t.New()